# -*- mode: python; coding: utf-8; -*-
##--------------------------------------------------------------------------##
##
## Copyright (C) 1998-2003 Markus Oberhumer <markus@oberhumer.com>
## Copyright (C) 2003 Mt. Hood Playing Card Co.
## Copyright (C) 2005-2010 Skomoroh <skomoroh@users.sourceforge.net>
## Copyright (C) 2010-2013 Jeremy Austin-Bardo <tjaustinbardo@gmail.com>
##
## This program is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program.  If not, see <http://www.gnu.org/licenses/>.
##
##--------------------------------------------------------------------------##
__docformat__ = "restructuredtext en"
__all__ = []

from ... import pilelib as stack
from ...gamelib import info as gi
from ...packlib import info as cs
from ...piles import tarock as tstack
from ...utillib.misc import kwdefault
from .. import klondike

Wrap = stack.StackWrapper
GT, SL = gi.GT, gi.SL


class ImperialTrumps(cs.Tarock_Deck, klondike.Klondike):
    """
    Finish 1 deck on _foundation_.

    :CVariables:
      _layout_ : pysollib.layout.Layout
        .. pysollib.layouts.klondike.KlondikeLayout

        - row [8 horz S foundation, vert offset]
        - talon [1 NW, no offset]
        - waste [1 E talon, no offset]
        - foundation [5 horz rows N, no offset]

      _talon_ : pysollib.stack.Stack
        .. pysollib.stack.WasteTalon (max_rounds=INFINITE)
        Deal 1 card per waste on click. Unlimited redeals.

      _waste_ : pysollib.stack.Stack
        .. pysollib.stack.WasteStack
        Init 1 card. Build none. Play top.

      _foundation_ : pysollib.stack.Stack
        .. pysollib.stacks.tarock.TrumpFirst_Foundation, stack.SS_Foundation
        Build up in rank by same suit with trump rank on 1st. Play top. Base
        ace or low trump.

      _row_ : pysollib.stack.Stack
        .. pysollib.stacks.tarock.HighTrumpAC_RowStack
        Init 1..8 card. Build suits down in rank by alt color and trump by
        rank alone. Play sequence. Base king or high trump.

      _hint_ : pysollib.hint.AbstractHint
        .. pysollib.hint.CautiousDefaultHint
    """
    __info__ = dict(id=158, name="Imperial Trumps", category=cs.TYPE_TAROCK,
                    game_type=GT.KLONDIKE | GT.POPULAR, decks=1, version='4.00',
                    redeals=cs.INFINITE, skill_level=SL.BALANCED)
    __author__ = 'Markus Oberhumer'
    __version__ = 7.70

    _foundations_ = (tstack.TrumpFirst_Foundation, stack.SS_Foundation,)
    _row_ = tstack.HighTrumpAC_RowStack

    def _create_game(self, **kw):
        l, s = self._layout_(self), self.s
        kwdefault(kw, rows=8, playcards=20)
        l.create(**kw)
        self.table_size = l.size
        s['talon'] = self._talon_(l.s['talon'].x, l.s['talon'].y, game=self)
        for r in l.s['wastes']:
            s['wastes'].append(self._waste_(r.x, r.y, game=self))
        for r in l.s['foundations']:
            i = 1 if r.suit == l.SUIT[-1] else 0
            s['foundations'].append(self._foundations_[i](r.x, r.y, game=self,
                                                      suit=r.suit))
        for r in l.s['rows']:
            s['rows'].append(self._row_(r.x, r.y, self))
        l.defaultAll()
        return l

PROVIDES = [ImperialTrumps]